package com.liwenfeng.diancanspringboot.mapper;

import com.github.pagehelper.Page;
import com.liwenfeng.diancanspringboot.annotation.AutoFill;
import com.liwenfeng.diancanspringboot.common.enumeration.OperationType;
import com.liwenfeng.diancanspringboot.pojo.dto.SetmealDTO;
import com.liwenfeng.diancanspringboot.pojo.dto.SetmealPageQueryDTO;
import com.liwenfeng.diancanspringboot.pojo.entity.Setmeal;
import com.liwenfeng.diancanspringboot.pojo.entity.SetmealDish;
import com.liwenfeng.diancanspringboot.pojo.vo.DishItemVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    Page<Setmeal> selectByPage(SetmealPageQueryDTO setmealPageQueryDTO);

    void delete(List<Long> ids);

    @AutoFill(OperationType.INSERT)
    @Insert("insert into setmeal (category_id, name, price, status, description, image, create_time, update_time, create_user, update_user) values (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, now(), now(), #{createUser}, #{updateUser})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Setmeal setmeal);

    @Select("select * from setmeal where id = #{id}")
    Setmeal getById(Long id);

    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    List<Setmeal> list(Setmeal setmeal);

    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long id);


    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    List<Setmeal> listByCategoryId(long categoryId);
}
